package cn.maszy.action.projectmanagement;

import java.util.List;
import java.util.UUID;

import net.sourceforge.stripes.action.SessionScope;

import org.springframework.beans.factory.annotation.Autowired;

import cn.maszy.common.BaseAction;
import cn.maszy.common.Pager;
import cn.maszy.common.SessionFactory;
import cn.maszy.model.projectmanagement.B_T_Flow_ProjectManagement;
import cn.maszy.model.projectmanagement.B_T_Ufp_Status;
import cn.maszy.model.projectmanagement.B_T_Ufp_TaskHandout;
import cn.maszy.model.projectmanagement.B_T_Ufp_TaskManager;
import cn.maszy.model.projectmanagement.C_T_Sys_File;
import cn.maszy.model.projectmanagement.C_T_Sys_FileType;
import cn.maszy.service.projectmanagement.B_T_Flow_ProjectManagementService;
import cn.maszy.service.projectmanagement.B_T_Ufp_TaskManagerService;
import cn.maszy.service.projectmanagement.C_T_Sys_FileService;
import cn.maszy.service.projectmanagement.C_T_Sys_FileTypeService;


@SessionScope
public class ProjectManagementAction extends  BaseAction<B_T_Flow_ProjectManagement>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Autowired
	private  B_T_Flow_ProjectManagementService b_T_Flow_ProjectManagementService;
	@Autowired
	private B_T_Ufp_TaskManagerService b_T_Ufp_TaskManagerService;
	@Autowired
	private C_T_Sys_FileTypeService c_T_Sys_FileTypeService;
	@Autowired
	private C_T_Sys_FileService c_T_Sys_FileService;
	private C_T_Sys_File c_T_Sys_File;
	private List<C_T_Sys_FileType> list_C_T_Sys_FileType;
	private B_T_Flow_ProjectManagement b_T_Flow_ProjectManagement;
	private B_T_Ufp_TaskManager b_T_Ufp_TaskManager;
	private Pager<B_T_Ufp_TaskManager> Pagers;
	private Pager<C_T_Sys_File> pagerFile;
	private String checkIds;
	private List<B_T_Ufp_Status> list_B_T_Ufp_Status;
	private List<B_T_Ufp_TaskHandout> list_B_T_Ufp_TaskHandout;
	private String moduleName;
	//定义查找带回判断所需查询
	private String flag;
	private String tab;
	/*********************class set/get****************************/
	public B_T_Flow_ProjectManagement getB_T_Flow_ProjectManagement() {
		return b_T_Flow_ProjectManagement;
	}
	public void setB_T_Flow_ProjectManagement(
			B_T_Flow_ProjectManagement b_T_Flow_ProjectManagement) {
		this.b_T_Flow_ProjectManagement = b_T_Flow_ProjectManagement;
	}
	public String getCheckIds() {
		return checkIds;
	}
	public void setCheckIds(String checkIds) {
		this.checkIds = checkIds;
	}
	public List<B_T_Ufp_Status> getList_B_T_Ufp_Status() {
		return list_B_T_Ufp_Status;
	}
	public void setList_B_T_Ufp_Status(List<B_T_Ufp_Status> listBTUfpStatus) {
		list_B_T_Ufp_Status = listBTUfpStatus;
	}
	public List<B_T_Ufp_TaskHandout> getList_B_T_Ufp_TaskHandout() {
		return list_B_T_Ufp_TaskHandout;
	}
	public void setList_B_T_Ufp_TaskHandout(
			List<B_T_Ufp_TaskHandout> listBTUfpTaskHandout) {
		list_B_T_Ufp_TaskHandout = listBTUfpTaskHandout;
	}
	public B_T_Ufp_TaskManager getB_T_Ufp_TaskManager() {
		return b_T_Ufp_TaskManager;
	}
	public void setB_T_Ufp_TaskManager(B_T_Ufp_TaskManager b_T_Ufp_TaskManager) {
		this.b_T_Ufp_TaskManager = b_T_Ufp_TaskManager;
	}
	public Pager<B_T_Ufp_TaskManager> getPagers() {
		return Pagers;
	}
	public void setPagers(Pager<B_T_Ufp_TaskManager> pagers) {
		Pagers = pagers;
	}
	public String getFlag() {
		return flag;
	}
	public void setFlag(String flag) {
		this.flag = flag;
	}
	public List<C_T_Sys_FileType> getList_C_T_Sys_FileType() {
		return list_C_T_Sys_FileType;
	}
	public void setList_C_T_Sys_FileType(
			List<C_T_Sys_FileType> list_C_T_Sys_FileType) {
		this.list_C_T_Sys_FileType = list_C_T_Sys_FileType;
	}
	public String getModuleName() {
		return moduleName;
	}
	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}
	
	public Pager<C_T_Sys_File> getPagerFile() {
		return pagerFile;
	}
	public void setPagerFile(Pager<C_T_Sys_File> pagerFile) {
		this.pagerFile = pagerFile;
	}
	public C_T_Sys_File getC_T_Sys_File() {
		return c_T_Sys_File;
	}
	public void setC_T_Sys_File(C_T_Sys_File c_T_Sys_File) {
		this.c_T_Sys_File = c_T_Sys_File;
	}
	public String getTab() {
		return tab;
	}
	public void setTab(String tab) {
		this.tab = tab;
	}
	/*******************STRUTS ACTION METHOD*************************/
	/**
	 * 修改isdelete为1
	 */
	public String projectmanagementDelUpdate()
	
	{
		int i=b_T_Flow_ProjectManagementService.updatekey(checkIds);
		if(i>0)
		return ajaxForwardSuccess(getText("msg.operation.success"), "ProjectmanagementList","", "forward", "projectmanagement/ProjectmanagementList?b_T_Flow_ProjectManagement.status=0");
		return ajaxForwardError(getText("msg.operation.failure"));
	}
	/**
	 * 关闭项目 修改状态值，1：关闭 0.未关闭
	 * @return
	 */
	public String proStatusUpdate(){
		int i=b_T_Flow_ProjectManagementService.statusUpdate(checkIds);
		if(i>0)
		return ajaxForwardSuccess(getText("msg.operation.success"), "ProjectmanagementList","", "forward", "projectmanagement/ProjectmanagementList?b_T_Flow_ProjectManagement.status=0");
		return ajaxForwardError(getText("msg.operation.failure"));
	}
	/**
	 * 插入
	 */
	public String projectmanagementUpdate()
	{
		int i=b_T_Flow_ProjectManagementService.update(b_T_Flow_ProjectManagement,flag);
		if(i>0)
		return ajaxForwardSuccess(getText("msg.operation.success"), "ProjectmanagementList","", "forward", "projectmanagement/ProjectmanagementList?b_T_Flow_ProjectManagement.status=0");
		return ajaxForwardError(getText("msg.operation.failure"));
	}
	/**
	 * 查看项目信息，编辑返回页面
	 * */
	public String projectmanagementUpdateDetail()
	{
		int i=b_T_Flow_ProjectManagementService.update(b_T_Flow_ProjectManagement,flag);
		if(i>0)
		return ajaxForwardSuccess(getText("msg.operation.success"), "ProjectmanagementReade","relxz", "closeCurrent", "projectmanagement/ProjectmanagementReade?b_T_Flow_ProjectManagement.projectUuid="+b_T_Flow_ProjectManagement.getProjectUuid()+"&moduleName=project&b_T_Ufp_TaskManager.taskSpeed=0");
		return ajaxForwardError(getText("msg.operation.failure"));
	}
	/**
	 * 查询
	 * @return
	 */

	public  String projectmanagementList() 
	{
		pager = new Pager<B_T_Flow_ProjectManagement>(pageNum, numPerPage,orderField,orderDirection);
		if("create_time".equals(pager.getOrderField())){
			pager.setOrderField("begin_time");
			pager.setOrderDirection("asc");
		}
		pager= b_T_Flow_ProjectManagementService.selectList(b_T_Flow_ProjectManagement,pager,flag);
		return SUCCESS;
	}
	/**
	 * 删除
	 * @return
	 */
	public String projectmanagementDel()
	{
		int i=b_T_Flow_ProjectManagementService.delete(checkIds);
		if(i>0)
		return ajaxForwardSuccess(getText("msg.operation.success"), "ProjectmanagementList", "","forward", "projectmanagement/ProjectmanagementList?b_T_Flow_ProjectManagement.status=0");
		return ajaxForwardError(getText("msg.operation.failure"));
	
	}
	//跳转到新建页面
	@SuppressWarnings("unused")
	public String projectmanagementJump()
	{
		if(b_T_Flow_ProjectManagement==null){
			b_T_Flow_ProjectManagement=b_T_Flow_ProjectManagementService.selectOne("");
			b_T_Flow_ProjectManagement.setStaffName(SessionFactory.getSessionUserRealNam());
			b_T_Flow_ProjectManagement.setProjectUuid(UUID.randomUUID().toString());
			flag="add";
		}else{
			//截取ID 适应页面局部排序
			String[] strUUid = b_T_Flow_ProjectManagement.getProjectUuid().split(",");
			for(int i = 0; i<strUUid.length; i++){
			//list_B_T_Ufp_TaskHandout = b_T_Flow_ProjectManagementService.queryTask(b_T_Flow_ProjectManagement.getProjectUuid());
			b_T_Flow_ProjectManagement=b_T_Flow_ProjectManagementService.selectOne(strUUid[i]);
			if(b_T_Ufp_TaskManager != null){
			Pagers = new Pager<B_T_Ufp_TaskManager>(pageNum, numPerPage,orderField,orderDirection);
			Pagers= b_T_Ufp_TaskManagerService.selectList(b_T_Ufp_TaskManager,Pagers,b_T_Flow_ProjectManagement.getProjectUuid());
			}
			break;
			}
			//查询附件类型
			C_T_Sys_FileType c_T_Sys_FileType = new C_T_Sys_FileType();
			list_C_T_Sys_FileType = c_T_Sys_FileTypeService.selectLists(c_T_Sys_FileType,moduleName);
			//查询项目下附件
			pagerFile = new Pager<C_T_Sys_File>(pageNum, numPerPage,orderField,orderDirection);
			pagerFile= c_T_Sys_FileService.selectLists(c_T_Sys_File,pagerFile,b_T_Flow_ProjectManagement.getProjectUuid(),flag);
			//调用UPDATE 判断是修改还是新增
			flag="edit";
		}
		return SUCCESS;
		
	}
	//项目任务追踪
	public String taskQuery(){
		Pagers = new Pager<B_T_Ufp_TaskManager>(pageNum, numPerPage,orderField,orderDirection);
		if("create_time".equals(Pagers.getOrderField())){
			Pagers.setOrderField("task_start_time");
			Pagers.setOrderDirection("ASC");
		}
		Pagers= b_T_Ufp_TaskManagerService.selectList(b_T_Ufp_TaskManager,Pagers,b_T_Flow_ProjectManagement.getProjectUuid());
		return SUCCESS;
	}

}
